#!/usr/bin/env python# -*- coding: utf-8 -*-# @Author  : Ailie# @File    : mailLogin.py# @Software: PyCharmimport timeimport unittestfrom selenium import webdriverfrom selenium.webdriver.support import expected_conditions as ECclass mailLogin(unittest.TestCase):
import unittest
from selenium import webdriver
import time
class Mail_login(unittest.TestCase):
        def setUp(self):
            url = 'https://mail.yeah.net/'
            self.browser = webdriver.Chrome()
            self.browser.get(url)
            time.sleep(5)
        def test_login_01(self):
            '''用户名、密码为空'''
            self.browser.switch_to.frame(0)
            self.browser.find_element_by_name('email').send_keys('')
            self.browser.find_element_by_name('password').send_keys('')
            self.browser.find_element_by_id('dologin').click()
            self.browser.switch_to.default_content()
            time.sleep(3)
            name = self.browser.find_element_by_id('spnUid')
            if name.text == 'a1730171685@yeah.net':
                print('登录成功')
            else:
                print('登陆失败')
        def test_login_02(self):
            '''用户名正确、密码为错误'''
            self.browser.switch_to.frame(0)
            self.browser.find_element_by_name('email').send_keys('a1730171685')
            self.browser.find_element_by_name('password').send_keys('xxxxxxx')
            self.browser.find_element_by_id('dologin').click()
            self.browser.switch_to.default_content()
            time.sleep(3)
            name = self.browser.find_element_by_id('spnUid')
            if name.text == 'a1730171685@yeah.net':
                print('登录成功')
            else:
                print('登陆失败')
        def test_login_03(self):
            '''用户名、密码正确'''
            # 第一种
            # self.browser.switch_to.frame(self.browser.find_element_by_xpath("//iframe[starts-with(@id, 'x-URS-iframe')]"))
            # self.browser.find_element_by_name('email').send_keys('a1730171685')
            # self.browser.find_element_by_name('password').send_keys('lzr0227..')
            # self.browser.find_element_by_id('dologin').click()

            # 第二种
            # iframe = self.browser.find_elements_by_tag_name("iframe")[0]
            # self.browser.switch_to.frame(iframe)

            # 第三种
            self.browser.switch_to.frame(0)
            self.browser.find_element_by_name('email').send_keys('a1730171685')
            time.sleep(1)
            self.browser.find_element_by_name('password').send_keys('lzr0227..')
            time.sleep(1)
            self.browser.find_element_by_id('dologin').click()
            self.browser.switch_to.default_content()
            time.sleep(3)
            name = self.browser.find_element_by_xpath('//span[@id="spnUid"]')
            print(name)
            print(type(name))
            value = 'a1730171685@yeah.net'
            if name.text == value:
                print('登录成功')
            else:
                print('登陆失败')
            time.sleep(3)
        def tearDown(self):
            self.browser.quit()


